/*
  Copyright (c) 2010 Les Newell. All rights reserved

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef MODULEDATA_H_INCLUDED
#define MODULEDATA_H_INCLUDED

#include "serial.h"
#include <vector>
#include <wx/ffile.h>

class Signal
{
public:
    Signal()
    {
        isInt = true;
        canWrite = false;
        value = 0;
        label = NULL;
        textCtrl = NULL;
        monitor = NULL;
    }

    wxString ToString()
    {
        if (isInt)
        {
            return(wxString::Format(_T("%i"),(int)value));
        }
        else
        {
            return(wxString::Format(_T("%f"),value));
        }
    }

    wxString GetId(const bool compact)
    {
        if(compact)
        {
            return(id);
        }
        return(name);
    }

    wxString name;
    bool isInt;
    bool canWrite;
    double value;
    wxString id;
    wxStaticText * label;
    wxTextCtrl * textCtrl;
    wxCheckBox * monitor;
};

class Module
{
public:
    wxString name;
    std::vector<Signal> signals;
};

class ModuleData : public std::vector<Module>
{
public:
    bool Save(const wxString& fileName, Serial * serial);
    bool Refresh(Serial * source);
    void ListModules(wxControlWithItems * target);
};

#endif

